#!/usr/bin/env bash

sed -i 's@^\\(deb.*stable main\\)$@#\\1\\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main stable main@' $PREFIX/etc/apt/sources.list
apt-get update

apt-get -y install git
apt-get -y install python3
pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/

mkdir yiban && cd yiban || exit
current_dir=$(pwd)
git clone https://gitee.com/litedream/fyiban
pip3 install -e fyiban
git clone https://gitee.com/litedream/yiban-sign && cd yiban-sign || exit
pip3 install -r requirements.txt
read -p "请输入易班账号: " username
read -p "请输入易班密码: " password
echo
read -p "请输入Server酱密钥: " secret_key
echo
cat > src/data/userData.py << EOF
users = [
    {
        'phone': '$username',
        'password': '$password',
        'serverChan': '$secret_key',
        "signChoices" : [
    {
        "enable": True,
        "LngLat": [118.884527,31.926239],
        "offsetRange": [0.00010, 0.00010],
        "Address":"江苏省 南京市 江宁区 学海路 南京工程学院体育公园",
    },
    {
        "enable": True,
        "LngLat": [118.881821,31.925585],
        "offsetRange": [0.00010, 0.00010],
        "Address":"江苏省 南京市 江宁区 淳化街道 日晖路 南京工程学院江宁校区",
    }
]
    }
]
EOF
mkdir -p /data/data/com.termux/files/home/.shortcuts
chmod 700 -R /data/data/com.termux/files/home/.shortcuts
mkdir -p /data/data/com.termux/files/home/.shortcuts/tasks
chmod 700 -R /data/data/com.termux/files/home/.shortcuts/tasks

echo "cd $current_dir/yiban-sign/src && python3 main.py" > /data/data/com.termux/files/home/.shortcuts/yiban-sign.sh
echo "安装完毕"
exit
